<template>
  <div>
    <el-header>
      <div style="display: flex; align-items: center;">
      <span style="margin-left: 10px;" @click="fanhui()" class="fuhao">
        <i class="el-icon-arrow-left"></i></span>
        <span class="zhong">商家详情</span>
      </div>
    </el-header>
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img class="images" v-lazy="image"/>
      </van-swipe-item>
    </van-swipe>
    <div class="table1">
      <van-cell-group v-for="item in tableData">
        <van-card>
          <template #tags>
            <div>
              <span class="score1">{{ item.xingjishu }}.00分</span>
              <span class="divider">{{ item.xingji }}</span>
              <div class="haoping3">
                <span class="haopin"><span class="haoping2">{{ item.gmrs }}个购买者给了好评</span></span></div>
            </div>
          </template>
        </van-card>
      </van-cell-group>
    </div>
    <!-- 好评数量部分 -->
    <div class="positive-reviews">
    </div>
  <div class="table2">
    <van-cell-group v-for="item in tableData">
      <van-card>
        <template #tags>
          <div>
            <span class="mdname">{{ item.mdname }}</span>
            <span class="danshu">{{ item.danshu }}w+单</span>
          </div>
        </template>
      </van-card>
    </van-cell-group>
  </div>

  <div class="weizhiall">
    <van-cell-group v-for="item in findWeizhi" class="group-daxiao">
      <van-card
          :title="item.yysj"
          :desc="item.dizhi"
      >
        <template #tags>
          <van-tag plain type="primary">
            <span>{{ item.fuwu }}</span>
          </van-tag>
        </template>
        <template #footer>
          <span class="x5">{{ (item.juli / 1000).toFixed(2) }} km</span>
          <van-button size="mini" class="yanse" @click="mendianditu">
            <van-icon name="guide-o" class="daohang"/>
            <br>
            <span>{{ item.daohang }}</span>
          </van-button>
          <van-button size="mini" class="yanse">
            <span>   <van-icon name="service-o" class="dianhua"/>
            <br><a href="tel:10086">点击可拨打</a></span>
          </van-button>
        </template>
      </van-card>
    </van-cell-group>
    <van-tabs>
      <van-tab title="优惠"></van-tab>
      <van-tab title="维修" v-model="value1" @change="aaa" :options="option2">
        <van-cell-group v-for="item in vehicles">
          <van-card
              :thumb=item.img
              :price=item.jiage
              :origin-price=item.zhekou
              :desc=item.pinlun
              :title=item.name
          >
            <template #tags>
              <van-tag plain type="primary" class="lanse">
                <span class="baise">{{ item.guanggao }}</span>
              </van-tag>
              <van-tag plain type="primary">
                <span>{{ item.ggw }}</span>
              </van-tag>
            </template>

            <template #footer>
              <van-button class="hongse" @click="qianggou(item.id)">抢购</van-button>
              <span class="taocan">没找到合适维修套餐<van-button class="hs" @click="weixiu()">更多项目></van-button></span>
            </template>
          </van-card>
        </van-cell-group>
      </van-tab>
      <van-tab title="清洗美容" v-model="value2" @change="bbb" :options="option2">
        <van-cell-group v-for="item in vehicles2">
          <van-card
              :thumb=item.img
              :price=item.jiage
              :origin-price=item.zhekou
              :desc=item.pinlun
              :title=item.name
          >
            <template #tags>
              <van-tag plain type="primary" class="lanse">
                <span class="baise">{{ item.guanggao }}</span>
              </van-tag>
              <van-tag plain type="primary">
                <span>{{ item.ggw }}</span>
              </van-tag>
            </template>
            <template #footer>
              <van-button class="hongse"  @click="qianggou(item.id)">抢购</van-button>
              <span class="taocan">没找到清洗美容套餐<van-button class="hs" @click="qingximeirong()">更多项目></van-button></span>
            </template>
          </van-card>
        </van-cell-group>
      </van-tab>
      <van-tab title="保养" v-model="value3" @change="ccc" :options="option2">
        <van-cell-group v-for="item in vehicles3">
          <van-card
              :thumb=item.img
              :price=item.jiage
              :origin-price=item.zhekou
              :desc=item.pinlun
              :title=item.name
          >
            <template #tags>
              <van-tag plain type="primary" class="lanse">
                <span class="baise">{{ item.guanggao }}</span>
              </van-tag>
              <van-tag plain type="primary">
                <span>{{ item.ggw }}</span>
              </van-tag>
            </template>
            <template #footer>
              <van-button class="hongse"  @click="qianggou(item.id)">抢购</van-button>
              <span class="taocan">没找到保养套餐<van-button class="hs" @click="baoyang()">更多项目></van-button></span>
            </template>
          </van-card>
        </van-cell-group>
      </van-tab>
    </van-tabs>
    <div id="mdpj">
      <div class="pingfen">
        <van-cell-group v-for="item in pingfen">
          <van-card>
            <template #tags>
              <div>
                <span class="mendian">{{ item.name }}</span>
                <span class="pinjia" @click="gengduo()">{{ item.pinjia }}条真实评价</span>
              </div>
              <br><br><br>
              <div>
                <span class="fenshu">{{ item.fenshu }}.00 分</span>
                <span class="xingji">{{ item.xingji }}</span>
                <span class="luntai">轮胎<br>{{ item.luntai }}.00</span>
                <span class="luntai">保养<br>{{ item.baoyang }}.00</span>
                <span class="luntai">洗美<br>{{ item.ximei }}.00</span>
                <span class="luntai">喷漆<br>{{ item.penqi }}.00</span>
              </div>
            </template>
          </van-card>
        </van-cell-group>
      </div>

    </div>
    <div class="pingjiaxinxi">
      <van-cell-group v-for="item in pingjiaxinxi">
        <van-card>
          <template #tags>
            <div> <span class="">
            <img class="touxiang" :src="item.touxiang"></span>
              <span class="mingzi">{{ item.name }}</span>
              <span class="qiche">{{ item.qiche }}</span>
              <span class="shijian">{{ item.shijian }}</span><br><br>
              <span class="xingji">{{ item.xingji }}</span>
              <span class="pinfen">{{ item.pinfen }}.00</span>
            </div>
            <br><br><br>
            <div>
              <span class="pinglun">{{ item.pinglun }}</span>
              <span class="zhaopian">
                <img :src="item.zhaopian">
              </span>
              <span class="zhaopian2">
                <img :src="item.zhaopian2">
              </span>
              <span class="suoxu">{{ item.xinxi }}</span>
            </div>
          </template>
        </van-card>
      </van-cell-group>
    </div>
    <div id="pingjia">
    <van-cell-group v-for="item in pingfen">
      <van-card>
        <template #tags>
          <button class="ping2" @click="gengduo()">查看更多评价({{ item.pinjia }})条</button>
            <span ></span>
        </template>
      </van-card>
    </van-cell-group>
    </div>
  </div>
    </div>
</template>

<script>
export default {
  name: "MendianXqView",
  data() {
    return {
      endLngLat:[],
      tableData: [],
      value1: 1,
      value2: 2,
      value3: 3,
      option2: [
        {text: '清洗美容', value: 3},
        {text: '保养', value: 2},
        {text: '维修', value: 1},
      ],
      ff: [],
      a: '',
// 经纬度
      Ra: '',
      Qa: '',
      city: '定位中...',
      findWeizhi: [],
      vehicles: [],
      vehicles2: [],
      pingjiaxinxi: [],
      vehicles3: [],
      images: [
        'https://hh666.oss-cn-beijing.aliyuncs.com/fb68d17b42a5b1e897d19f1f9d354656.jpeg',
        'https://hh666.oss-cn-beijing.aliyuncs.com/ffb5bb8fa0fffa31a5a9fb05a0beaffb.jpeg',
        'https://hh666.oss-cn-beijing.aliyuncs.com/ffb5bb8fa0fffa31a5a9fb05a0beaffb.jpeg',
        'https://hh666.oss-cn-beijing.aliyuncs.com/ffb5bb8fa0fffa31a5a9fb05a0beaffb.jpeg',
      ],
    }
  },
  methods: {
    mendianditu(){
      // location.href=`https://lbs.amap.com/demo/javascript-api-v2/example/location/browser-location`
      console.log("endLngLat",this.endLngLat)
      this.$router.push({path: '/mendianditu', query: {a: this.endLngLat}})
    },
    aaa(val) {
      this.value1 = val
      this.mendianzhanshi()
    },
    bbb(val) {
      this.value2 = val
      this.mendianzhanshi2()
    },
    ccc(val) {
      this.value3 = val
      this.mendianzhanshi3()
    },
    fanhui() {
      this.$router.go(-1)
    },
    findMendianAllXq() {
      var mid = this.$route.query.mid
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/findMendianAllXq?mid=${mid}`).then(res => {
        this.tableData = res.data
      })
    },
    mendianweizhi() {
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/findmendianWeizhiAll`).then(res => {
        this.findWeizhi = res.data
      })
    },
    mendianzhanshi() {
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/mendianzhanshi?value1=${this.value1}`).then(res => {
        // console.log(res.data)
        this.vehicles2 = res.data
      })
    },

    mendianzhanshi2() {
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/mendianzhanshi2?value2=${this.value2}`).then(res => {
        // console.log(res.data)
        this.vehicles3 = res.data
      })
    },
    mendianzhanshi3() {
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/mendianzhanshi3?value3=${this.value3}`).then(res => {
        // console.log(res.data)
        this.vehicles = res.data
      })
    },
    pingfen() {
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/pingfen`).then(res => {
        // console.log(res.data)
        this.pingfen = res.data
      })
    },
    pinjiaxinxi() {
      this.axios.post(`http://1.94.221.254:9999/api-qcfw-mendian/mendian/pingjiaxinxi`).then(res => {
        // console.log(res.data)
        this.pingjiaxinxi = res.data
        // console.log(55555555555)
        // console.log(this.pingjiaxinxi)
      })
    },
    qianggou(id){
      this.$router.push({path: '/qianggou', query: {id: id}})
    },
    gengduo(){
      this.$router.push('/gengduo')
    },
    baoyang(){
      this.$router.push('/baoyang')
    },
    qingximeirong(){
      this.$router.push('/qingxi')
    },
    weixiu(){

    },
    //获取当前地理位置
    addresaaa() {
      this.axios.get(`https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=${this.abcde}&key=497c66a7bfeda317880776a6d296ca5f&radius=1000&extensions=all `).then(res => {
            // 获取市级
            // this.city.qu=res.data.regeocode.addressComponent.district
            // 获取区级

            this.city = res.data.regeocode.addressComponent.province
            console.log("当前地理位置：" + this.city)
          }
      )
    },
    // 测试目的地的经纬度坐标
    async nnnn(value) {

      const res = await this.axios.get(`https://restapi.amap.com/v3/geocode/geo?address=${value}&output=JSON&key=497c66a7bfeda317880776a6d296ca5f`);
      console.log("res",res)
      this.ff = res.data;
      this.a = this.ff.geocodes[0].location;  // 使用 optional chaining 防止空值错误
      this.endLngLat=this.a
      await this.fanhui1();  // 等待 fanhui 执行完成

    },
// 返回多少米
    async fanhui1() {

      const res = await this.axios.get(`https://restapi.amap.com/v3/distance?origins=${this.abcde}&destination=${this.a}&output=JSON&key=497c66a7bfeda317880776a6d296ca5f`);
      this.a = res.data.results[0].distance;  // 使用 optional chaining 防止空值错误

    },

// 测修车店的距离
    async getjuliyy() {
      setTimeout(async () => {
        // 遍历所有修车店并计算距离
        for (const item of this.findWeizhi) {
          const mudidi = item.dizhi;
          await this.nnnn(mudidi);  // 等待 nnnn 完成
          item.juli = this.a;  // 将计算的距离赋给修车店
        }
      }, 3000);
    },

  },
  created() {
    this.mendianzhanshi();
    this.findMendianAllXq();
    this.mendianweizhi()
    this.mendianzhanshi2()
    this.mendianzhanshi3()
    this.pingfen()
    this.pinjiaxinxi()
    // 延迟获取地理位置
    setTimeout(() => {
      this.Ra = sessionStorage.getItem("R");
      this.Qa = sessionStorage.getItem("Q");
      console.log("执行已完成")
      console.log("经度=====" + this.Ra)
      console.log("纬度=====" + this.Qa)
      this.abcde = this.Ra + ',' + this.Qa
      console.log("合起来：" + this.abcde)
      this.addresaaa();
    }, 1);
    this.getjuliyy();
    var token = localStorage.getItem('token');
    if (token === null) {
      this.$router.push('/');
    }
  }
}
</script>
<style scoped>
.yanse{
  background-color: #FAFAFA;
}
.ping2{
  height: 30px;
  width: 100%;
}
#pingjia{
  width: 100%;
  height: 30px;
  background-color: #FAFAFA;
}
.table2{
  //margin-top: -40px;
}
.table1{
  //border: 1px solid #000000;
  margin-top: -40px;
  height: 55px;
}
.weizhiall{
  margin-top: -60px;
}
.suoxu {

}

.zhaopian {
  margin-top: 5px;
  //padding-left: 5px;
}

.zhaopian2 {
  margin-top: 5px;
  padding-left: 10px;
}

.pinfen {
  padding-left: 10px;
  margin-top: 6px;
}

.shijian {
  float: right;
}

.qiche {
  padding-left: 5px;
}

.mingzi {
  padding-left: 5px;
}

.touxiang {
  width: 20px;
  height: 20px;
}

.luntai {
  padding-left: 15px;
}

.xingji {
  font-size: 8px;
  margin-top: 6px;
  padding-left: 5px;
  color: #FB4D03;
}

.fenshu {
  font-size: 20px;
  color: #FB4D03;
}

.mendian {
  font-size: 20px;
}

.pinjia {
  float: right;
}

.zhong {
  margin-left: 115px;
  margin-top: 10px;
}

.mdname {
  margin-left: 70px;
  font-size: 17px;
}

.danshu {
  float: right;
  margin-top: 5px;
  font-size: 7px;
  border: 1px solid rgb(23, 22, 22);
}

.tab {
  border-bottom: none;
  margin-top: -50px;
}

.images {
  width: 90%;
  padding-left: 20PX;
  height: 200px;
}

.rating {
  display: flex;
  align-items: center;
  background-color: #800000;
}

jiage {
  color: rgba(220, 16, 16, 0.95);
}
.fuhao{
  margin-top: 12px;
  padding-left: -30px;
}
button {
  border: none;
}

h4 {
  padding-left: 15px;
}

.taocan {
  padding-left: 50px;
  margin-top: 5px;
}

.score1 {
  font-size: 20px;
  color: #00ffb2;
  margin-right: 10px;
}

.daohang {
  font-size: 25px;
}

#mdpj {
  //border: 1px solid #171616;
  width: 100%;
}

.pingfen {
  //border: 1px solid #000000;
  width: 365px;
  height: 100px;
  border-radius: 10px;
  margin: 10px;
  background-color: #F6F6F6;
}


.hs {
  color: #FB4D03;
  background-color: #FAFAFA;
  font-size: 12px;
}

.dianhua {
  font-size: 25px;
}

.stars i {
  font-size: 20px;
  color: #FF9800;
}

.positive-reviews {
  float: left;
  font-size: 14px;
  color: #666;
  margin-left: 130px;
  background-color: #00805a;
}

.group-daxiao {
}

.hongse {
  background-color: #FB4D03;
  border-radius: 40px;
  color: #eeeeee;
  width: 80px;
}

.score1 {
  border: 1px solid #FF9800;
  color: #F4F6DE;
  padding: 5px 10px;
  margin-top: -8px;
  background-color: #FB4D03;
  border-radius: 10px;
  height: 40px;
}

.divider {
  font-size: 10px;
  padding-top: 25px;
  margin-left: -85px;
}

.lanse {
  background-color: #007bff;
}

.baise {
  color: #fff;
}

.beijing {
  background-color: #00805a;
}

.haopin {
  float: left;
  padding-top: 10px;
  margin-left: -10px;
  height: 15px;
  width: 270px;
  background-color: #FBF7EC;
}
.haoping2{
  margin-left: 20px;
  margin-top: -10px;
}
.haoping3{
  padding-top: 13px;
}

</style>
